package unilearn.facade;

import java.sql.SQLException;
import java.util.Vector;

import javax.naming.NamingException;

import unilearn.da.DASubmission;
import unilearn.domain.Assessment;
import unilearn.domain.Assignment;
import unilearn.domain.DataFile;
import unilearn.domain.Submission;

/**
 * @author Ben Morall, 4158768
 * @version 0.1, 25 April 2008, inital creation, blm
 */
public class SubmissionFacade
{

	public static Submission createNewSubmission(Assignment assignment, DataFile file,
			String studentNumber) throws SQLException, NamingException
	{
		if (assignment == null) { throw new NullPointerException("assignment"); }

		long assignmentID = assignment.getID();
		if (assignmentID == -1) throw new IllegalArgumentException("assignmentID = -1");
		long fileID = file.getFileID();
		if (fileID == -1) throw new IllegalArgumentException("fileID = -1");

		Submission sub = new Submission();
		sub.setAssignmentID(assignmentID);
		sub.setStudentNumber(studentNumber);
		sub.setFileID(fileID);

		return DASubmission.insertSubmission(sub);
	}

	@Deprecated
	public static Submission createNewSubmission(Assignment assignment, DataFile file,
			String studentNumber, String STAFF_MEMBER) throws SQLException, NamingException
	{
		if (assignment == null) { throw new NullPointerException("assignment"); }

		long assignmentID = assignment.getID();
		if (assignmentID == -1) throw new IllegalArgumentException("assignmentID = -1");
		long fileID = file.getFileID();
		if (fileID == -1) throw new IllegalArgumentException("fileID = -1");

		Submission sub = new Submission();
		sub.setAssignmentID(assignmentID);
		sub.setStudentNumber(studentNumber);
		sub.setFileID(fileID);
		sub.setStaffID(STAFF_MEMBER);

		return DASubmission.insertSubmissionBAD(sub);
	}

	public static boolean deleteSubmission(Submission submission) throws SQLException,
		NamingException

	{
		long submissionID = submission.getSubmissionID();

		return DASubmission.deleteSubmission(submissionID);
	}

	public static Submission getSubmission(long submissionID) throws SQLException,
		NamingException
	{
		return DASubmission.getSubmission(submissionID);
	}

	public static Submission getSubmission(Assessment assessment) throws SQLException,
		NamingException
	{
		long assessmentID = assessment.getAssessmentID();

		return DASubmission.getSubmission(assessmentID);
	}

	public static Vector<Submission> getAssignmentSubmissions(long assignmentID)
		throws SQLException, NamingException
	{
		return DASubmission.getSubmissionsByAssignment(assignmentID);
	}

	public static Vector<Submission> getSubmissions(Assignment assignment)
		throws SQLException, NamingException
	{
		long assignmentID = assignment.getID();

		return getAssignmentSubmissions(assignmentID);
	}

	public static Vector<Submission> getSubmissions(String studentNumber)
		throws SQLException, NamingException
	{
		return DASubmission.getSubmissionsByStudent(studentNumber);
	}

	public static Vector<Submission> getSubmissionsByStaff(String staffID)
		throws SQLException, NamingException
	{
		return DASubmission.getSubmissionsByStaff(staffID);
	}

	@Deprecated
	public static String[] getStudentNumbers() throws SQLException, NamingException
	{
		return DASubmission.getStudentNumbers();
	}

	public static void updateSubmission(Submission submission, DataFile file)
		throws SQLException, NamingException
	{
		long submissionID = submission.getSubmissionID();
		long fileID = file.getFileID();

		DASubmission.updateSubmission(submissionID, fileID);
		submission.setFileID(fileID);
	}
}
